import { NextResponse } from 'next/server'

import { getAvailableApiSites, getCacheTime } from '@/lib/config'

export const runtime = 'nodejs'

// OrionTV 兼容接口
export async function GET() {
  try {
    const apiSites = await getAvailableApiSites()
    const cacheTime = await getCacheTime()

    return NextResponse.json(apiSites, {
      headers: {
        'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
        'CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
        'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
      },
    })
  }
  catch {
    return NextResponse.json({ error: '获取资源失败' }, { status: 500 })
  }
}
